const { contextBridge, ipcRenderer } = require('electron')

// 暴露受保护的方法到渲染进程
contextBridge.exposeInMainWorld('electronAPI', {
  // 示例：发送消息到主进程
  send: (channel, data) => {
    const validChannels = ['toMain']
    if (validChannels.includes(channel)) {
      ipcRenderer.send(channel, data)
    }
  },
  // 示例：接收主进程消息
  receive: (channel, func) => {
    const validChannels = ['fromMain']
    if (validChannels.includes(channel)) {
      ipcRenderer.on(channel, (event, ...args) => func(...args))
    }
  },
  // 下载图片列表
  downloadImages: (imageList) => {
    return ipcRenderer.invoke('download-images', imageList)
  },
})

